package com.train.member.mapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.train.common.model.page.PageSorted;
import com.train.common.resp.PageResp;
import com.train.member.resp.passenger.PassengerListResp;
import com.train.member.resp.passenger.PassengerPageResp;
import com.train.member.dto.PassengerPageDTO;
import com.train.member.po.PassengerPO;
import com.train.mybatis.base.MyBaseMapper;

import java.util.List;

/**
* @author baitiaojun
* @description 针对表【passenger(乘车人)】的数据库操作Mapper
* @createDate 2025-02-14 19:37:18
* @Entity generator.domain.Passenger
*/
public interface PassengerMapper extends MyBaseMapper<PassengerPO> {

    default boolean existsMemberId(Long memberId, String idCard) {
        LambdaQueryWrapper<PassengerPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PassengerPO::getMemberId, memberId).eq(PassengerPO::getIdCard, idCard);
        return this.exists(queryWrapper);
    }

    default PageResp<PassengerPageResp> pageList(PassengerPageDTO passengerPageDTO) {
        PageResp<PassengerPO> passengerPOPageResp = this.selectPage(
                passengerPageDTO,
                new LambdaQueryWrapper<>(), new PageSorted(PassengerPO::getUpdateTime), new PageSorted(PassengerPO::getCreateTime));
        List<PassengerPageResp> passengerPageRespList = BeanUtil.copyToList(passengerPOPageResp.getData(), PassengerPageResp.class);
        return new PageResp<>(passengerPOPageResp.getTotal(), passengerPageRespList);
    }

    default boolean existsId(Long id) {
        LambdaQueryWrapper<PassengerPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PassengerPO::getId, id);
        return this.exists(queryWrapper);
    }

    default List<PassengerListResp> selectPassengerList(Long userId) {
        LambdaQueryWrapper<PassengerPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PassengerPO::getMemberId, userId)
                .orderBy(true, true, PassengerPO::getName);
        List<PassengerPO> passengerPOS
                = this.selectList(queryWrapper);
        return BeanUtil.copyToList(passengerPOS, PassengerListResp.class);
    }
}




